package net.eascn.Editor.dao
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	
	import mx.controls.Alert;
	
	import net.eascn.Editor.model.ModelLocator;
	
	public class Provider
	{
		public function Provider()
		{
		}
		
//		
//		
		public function getAlbumType():void
		{
			if(ModelLocator.getInstance().catalogueXML)
				return;
			var urlloader:URLLoader = new URLLoader();
			urlloader.addEventListener(Event.COMPLETE,getAlbumTypeHandler);
			var urlrequ:URLRequest = new URLRequest();
			urlrequ.url ='http://www.gift4.com.cn/cgi-common/user/ac-result.php';
			var urlParm:URLVariables = new URLVariables();
			urlParm['action']= 'query_album_type';
			urlrequ.data = urlParm;
			urlrequ.method = 'post';
			urlloader.load(urlrequ);
		}
		
		private function getAlbumTypeHandler(event:Event):void
		{
			var data:String = event.currentTarget.data;
			var dxml:XML = XML(data);
			ModelLocator.getInstance().catalogueXML = dxml.children();
		}
		
		
		public function getAlbumStandard():void
		{
			if(ModelLocator.getInstance().standardXML)
				return;
			var urlloader:URLLoader = new URLLoader();
			urlloader.addEventListener(Event.COMPLETE,getAlbumStandardHandler);
			var urlrequ:URLRequest = new URLRequest();
			urlrequ.url ='http://www.gift4.com.cn/cgi-common/user/ac-result.php';
			var urlParm:URLVariables = new URLVariables();
			urlParm['action']= 'query_album_standard';
			urlrequ.data = urlParm;
			urlrequ.method = 'post';
			urlloader.load(urlrequ);
		}
		
		private function getAlbumStandardHandler(event:Event):void
		{
			var data:String = String(event.currentTarget.data);
			var dxml:XML =  XML(data);
			ModelLocator.getInstance().standardXML = dxml.children();
		}
		
		
		public function saveAlbumTemplate(tplname:String,tpldata:String,typeid:String,photoid:String):void
		{
			var urlloader:URLLoader = new URLLoader();
			urlloader.addEventListener(Event.COMPLETE,saveAlbumTemplateHandler);
			var urlrequ:URLRequest = new URLRequest();
			urlrequ.url ='http://www.gift4.com.cn/cgi-common/user/ac-result.php';
			var urlParm:URLVariables = new URLVariables();
			urlParm['action']= 'new_albumtpl';
			urlParm['tplname']= tplname;
			urlParm['tpldata']= tpldata;
			urlParm['typeid']= typeid;
			urlParm['photoid']= photoid;
			
			urlrequ.data = urlParm;
			urlrequ.method = 'post';
			urlloader.load(urlrequ);
		}
		
		private function saveAlbumTemplateHandler(event:Event):void
		{
			var data:String = String(event.currentTarget.data);
			var dxml:XML =  XML(data);
			Alert.show(dxml.message);
		}
		
	}
}